package com.mqtt.demo.controller;

import com.mqtt.demo.constant.Constant;
import com.mqtt.demo.mqtt.MyMqttClient;
import jakarta.annotation.Resource;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName MessageController
 * @Description TODO
 * @Author zhengmw
 * @Data 2024/7/25 20:04
 */
@RequestMapping("/message")
@RestController
public class MessageController {

    @Resource
    private MyMqttClient mqttClient;

    /**
     * @Description 消息发送
     *
     * @Return void
     * @Author zhengmw
     * @Date 2024/7/25 20:05
     */
    @GetMapping("/send")
    public void send(String message) throws MqttException {
        mqttClient.publish(Constant.PUBLIC_TOPIC, message);
    }
}
